package com.cindata

import com.cindata.dictionary.*

class Developer
{
    Province province
    // 省
    City city
    // 城市
    District district
    String companyId
    //开发商Id
    String name
    // 开发商名称
    OrganizationNatureDict unitNature
    // 单位性质
    String unifiedSocialCreditCode
    // 统一社会信用代码
    String status
    // 企业状态 在营, 在册, 开业
    String operatingState
    // 经营状态
    String registrationNumber
    // 注册号
    BigDecimal registeredCapital
    // 注册资金（万元）
    String registeredcur
    //注册资金单位
    String creditRating
    // 开发商信用等级
    String qualificationGrade
    // 开发资质
    String legalRepresentative
    // 法定代表人
    String legalRepresentativeCredit
    // 法定代表人信用资质
    Integer caseOfComplaintAmount
    // 企业涉诉情况数量
    Double assetRatio
    // 资产负债率
    String entryStatus
    // 入围状态
    String address
    // 企业地址
    String manageGroup
    // 所属集团
    String financialOfficer
    // 财务负责人
    String phone
    // 咨询电话
    String scopeOfBusiness
    // 经营范围
    String type
    // 企业类型
    String industry
    // 所属行业、行业门类
    Date establishDate
    // 成立日期
    Integer operatingPeriod
    // 经营期限
    String operatingYears
    // 经营年限 2015-02-05 至 2099-12-31
    Date approvalDate
    // 核准日期
    String registerOrg
    // 登记机关
    Date registerDate
    // 工商登记日
    Date logoutDate
    // 注销日期
    Date revocationDate
    // 吊销日期

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User user
    User createBy
    User modifyBy

    static hasMany = [projects: DeveloperProject]

    static constraints = {
        province nullable: true, blank: true, comment: '省'
        city nullable: true, blank: true, comment: '城市'
        district nullable: true, blank: true, comment: '行政区'
        companyId nullable: true, blank: true, comment: '开发商Id'
        name maxSize: 60, nullable: true, blank: true, comment: '开发商名称'
        unitNature nullable: true, blank: true, comment: '单位性质'
        unifiedSocialCreditCode maxSize: 32, nullable: true, blank: true, comment: '统一社会信用代码'
        status nullable: true, blank: true, comment: '企业状态'
        operatingState nullable: true, blank: true, comment: '经营状态'
        registrationNumber nullable: true, blank: true, comment: '经营状态'
        registeredCapital nullable: true, blank: true, precision: 15, scale: 2, comment: '注册资金'
        registeredcur nullable: true, blank: true, comment: '注册资金单位'
        creditRating nullable: true, blank: true, comment: '开发商信用等级'
        qualificationGrade nullable: true, blank: true, comment: '开发资质'
        legalRepresentative maxSize: 20, nullable: true, blank: true, comment: '法定代表人'
        legalRepresentativeCredit maxSize: 20, nullable: true, blank: true, comment: '法定代表人信用资质'
        caseOfComplaintAmount nullable: true, blank: true, comment: '企业涉诉情况数量'
        assetRatio nullable: true, blank: true, comment: '资产负债率'
        entryStatus nullable: true, blank: true, comment: '资产负债率'
        address maxSize: 128, nullable: true, blank: true, comment: '入围状态'
        manageGroup maxSize: 60, nullable: true, blank: true, comment: '所属集团'
        financialOfficer maxSize: 20, nullable: true, blank: true, comment: '财务负责人'
        phone maxSize: 20, nullable: true, blank: true, comment: '放款日期'
        scopeOfBusiness nullable: true, blank: true
        type nullable: true, blank: true
        industry nullable: true, blank: true
        establishDate nullable: true, blank: true
        operatingPeriod nullable: true, blank: true
        operatingYears nullable: true, blank: true
        approvalDate nullable: true, blank: true
        registerOrg nullable: true, blank: true
        registerDate nullable: true, blank: true
        logoutDate nullable: true, blank: true
        revocationDate nullable: true, blank: true

        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        user nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
    }

    def toHM()
    {
        def hashObj = [id: this.id,
            name: this?.name,
            unifiedSocialCreditCode: this?.unifiedSocialCreditCode,
            parentId: null,
            phone: this?.phone,
            address: this?.address,
            manageGroup: this?.manageGroup,
            registeredCapital: this?.registeredCapital,
            legalRepresentative: this?.legalRepresentative,
            financialOfficer: this?.financialOfficer,
            children: []]
        return hashObj
    }

    static ToHashMapArr(developerArr)
    {
        def hashArr = []
        developerArr.each {
            hashArr.push(it.toHM())
        }
        return hashArr
    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}



